package ${package.Controller};

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import ${package.Entity}.layuiBean.ResultPage;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;

import ${package.Entity}.${entity};
import com.plan.commen.bean.layuiBean.ResultPage;
import com.plan.commen.entity.ApiResult;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.plan.commen.entity.BaseController;
import com.plan.commen.bean.layuiBean.VoPage;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("/admin/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} extends BaseController{
</#if>

     /** 主页面 */
    @RequestMapping("main.html")
    public String main(){
       return  "/admin/${cfg.entityfineName}/${cfg.entityfineName}Main";
    }

    /** 添加页面跳转
     * @return 返回页面
     */
    @RequestMapping(value = "/add.html")
    public String add${cfg.entityName}Html( ){
        return "/admin/${cfg.entityfineName}/${cfg.entityfineName}Add";
    }

    /** 编辑页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "/edit.html")
    public String edit${cfg.entityName}Html(String id ,Model model ){
       model.addAttribute("${cfg.entityfineName}",${cfg.entityfineName}Service.getById(id));
       return "/admin/${cfg.entityfineName}/${cfg.entityfineName}Edit";
    }

    /** 查看页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "/show.html")
    public String show${cfg.entityName}Html(String id ,Model model ){
        model.addAttribute("${cfg.entityfineName}",${cfg.entityfineName}Service.getById(id));
        return "/admin/${cfg.entityfineName}/${cfg.entityfineName}Show";
    }


    /** 分页查询${cfg.entityName}
     * @param ${cfg.entityfineName}  前端传进的参数
     * @return 返回统一分页信息
     */
    @RequestMapping(value = "/find${cfg.entityName}ByPage")
    @ResponseBody
    public ResultPage find${cfg.entityName}ByPage(VoPage voPage,${cfg.entityName} ${cfg.entityfineName}){
        return ${cfg.entityfineName}Service.find${cfg.entityName}ByPage(voPage,${cfg.entityfineName});
    }

    /** 添加${cfg.entityName}
     * @param ${cfg.entityfineName}  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "/saveOrUpdate${cfg.entityName}")
    @ResponseBody
    public ApiResult saveOrUpdateById${cfg.entityName}(@RequestBody ${cfg.entityName} ${cfg.entityfineName}  ){
        ${cfg.entityfineName}.setCreateTime(System.currentTimeMillis());
        if(${cfg.entityfineName}Service.saveOrUpdate(${cfg.entityfineName})){
            return ApiResult.ok();
        }else{
            return ApiResult.fail();
        }
    }





    /** 删除一条${cfg.entityName}
     * @param id  前端传进的ID
     * @return 返回统一信息
     */
    @RequestMapping(value = "/del_${cfg.entityName}")
    @ResponseBody
    public ApiResult del${cfg.entityName}( String id  ){
        if(${cfg.entityfineName}Service.removeById(id)){
            return ApiResult.ok();
        }else{
            return ApiResult.fail();
        }
    }


}
</#if>
